package com.zeratul.common.core.exception;

import com.zeratul.common.core.result.codes.ResultCodes;
import lombok.Getter;

/**
 * 自定义业务异常
 */
@Getter
public class ServiceException extends RuntimeException {

    /**
     * 响应码
     */
    private Integer code;

    /**
     * 响应信息
     */
    private String msg;

    /**
     * 数据部分
     */
    private Object data;

    /**
     * 全参构造方法
     */
    public ServiceException(Integer code, String msg, Object data) {
        super(msg);
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 根据ResultCode生成业务异常
     * @param resultCodes
     */
    public ServiceException(ResultCodes resultCodes) {
        this(resultCodes.getCode(), resultCodes.getMessage(), null);
    }

    /**
     * 根据ResultCode 和 数据生成业务异常
     * @param resultCodes
     */
    public ServiceException(ResultCodes resultCodes, Object data) {
        this(resultCodes.getCode(), resultCodes.getMessage(), data);
    }

    /**
     * 根据异常内容生成异常对象
     * @param msg
     */
    public ServiceException(String msg) {
        this(ResultCodes.FAIL.getCode(), msg, null);
    }
}
